package java_thinking.unit_14._14_4;

/**
 * @Description : instanceof与isInstance结果相同，==和equals结果相同
 * instanceof 指的是“你是这个类吗，你是这个类的派生类吗”，而==比较实际的class对象，没有考虑继承
 * @author: cww
 * @DateTime: 2019-03-30 14:47
 */
class Base{};
class Derived extends Base{};
/**
 * @author asd730520@live.com
 */
public class FamilyVsExactType {
    static void test(Object x){
        System.out.println("Testing x of Type  "+x.getClass());
        System.out.println("x instanceof Base  "+(x instanceof Base));
        System.out.println("x instanceof Derived  "+(x instanceof Derived));
        System.out.println("Base.isInstance(x)  "+Base.class.isInstance(x));
        System.out.println("Derived.isInstance(x)  "+Derived.class.isInstance(x));
        System.out.println("==========================================================");
        System.out.println("x.getClass()==Base.class  "+(x.getClass()==Base.class));
        System.out.println("x.getClass()==Derived.class  "+(x.getClass()==Derived.class));
        System.out.println("x.getClass().equals(Base.class  )"+(x.getClass().equals(Base.class)));
        System.out.println("x.getClass().equals(Derived.class  )"+(x.getClass().equals(Derived.class)));
    }
    public static void main(String[] args){
        test(new Base());
        test(new Derived());
    }
}
